<?php

require_once "../include/connectionHandlers/database/Voyage.php";
require_once "../include/connectionHandlers/database/Categorie.php";
require_once "../include/connectionHandlers/database/Article.php";

class gallerySelector_controller
{
	const VOYAGE = "Voyage";
	const CATEGORIE = "Categorie";
	const ARTICLE = "Article";
	private $selectorType;
	
	public function __construct($selectorTypeT)
	{
		$this->selectorType = $selectorTypeT;
		if(isset($_POST["Submit".$this->selectorType])){
			if(isset($_POST["TextBox".$this->selectorType])){
				switch($this->selectorType)
				{
					case self::VOYAGE:
				
						$this->insertVoyage($_POST["TextBoxVoyage"]);
						break;
					case self::CATEGORIE:
				
						$this->insertCategorie($_POST["TextBoxCategorie"]);
						break;
					case self::ARTICLE:
				
						$this->insertArticle($_POST["TextBoxArticle"]);
						break;
					default:
						return;
				}
				
			}			
		}		
	}
	
	public function setType($selectorTypeT)
	{
		$this->selectorType = $selectorTypeT;	
	}
	
	public function displayDropDownList()
	{
		$listToDisplay = array();
		switch ($this->selectorType)
		{
			case self::VOYAGE:
				
				$listToDisplay = $this->getVoyages();
				break;
			case self::CATEGORIE:
				
				$listToDisplay = $this->getCategories();
				break;
			case self::ARTICLE:
				
				$listToDisplay = $this->getArticles();
				break;
			default:
				return;
		}
		echo "<select>";
		echo "<option value='' selected='selected'>Selectionner</option>";
		foreach($listToDisplay as $key=>$value){
			echo "<option value='".$key."'>".$value["name"]."</option>";
		}
		echo "</select>";
		return;
	}
	
	private function getVoyages()
	{
		$voyages = new Voyage();
		$allTrips = $voyages->selectAll();
		
		return $allTrips;
	}
	private function getCategories()
	{
		$categories = new Categorie();
		$allCategories = $categories->selectAll();
		
		return $allCategories;
	}
	private function getArticles()
	{
		$articles = new Article();
		$allArticles = $articles->selectAll();
		
		return $allArticles;
	}
		private function insertVoyage($voyage)
	{
		$voyages = new Voyage();
		$parameters = array($voyage,NULL,NULL,NULL,NULL);
		$voyages->insert($parameters);
		
		return;
	}
	private function insertCategorie($categorie)
	{
		$categories = new Categorie();
		$parameters = array($categorie,NULL);
		$allCategories = $categories->insert($parameters);
		
		return;
	}
	private function insertArticle($article)
	{
		$articles = new Article();
		$parameters = array($article,NULL,NULL,NULL,NULL);
		$allArticles = $articles->insert($parameters);
		
		return;
	}
	
}
?>